package TeatCase;

import android.graphics.Point;
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiObject2;
import android.util.Log;
import static  HomeElements.AssertElementsContent.*;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import QunarTest.QuanrTestCase;
import util.UIHelper;

/**
 * Created by zhe.xiao on 2017/7/24.
 */
@RunWith(AndroidJUnit4.class)
public class TestPush extends QuanrTestCase{
    @Test
    public void testPush(){
        UIHelper.getHomeElements().getMessage().click();
        boolean b = false;
        while(!b) {
            int i = 0;
            UiObject2 u2 = null;
            List<UiObject2> el = UIHelper.getPushElements().getElementList();
            for (UiObject2 o : el) {
                Log.i("UIAUTOMATOR", "ELEME" + o.getVisibleCenter());
                String text = o.getText();
                Log.v("UIAUTOMATOR", "testPush: " + text);
                o.click();
                UIHelper.getElementsAction().assertFalse(pushDes(), text);
                UIHelper.getElementsAction().back();
                if(i == el.size()-1){
                    u2 = o;
                }else{
                    i++;
                }
            }
            if (u2 != null) {
                Point p = UIHelper.getElementsAction().getElementConcent(u2);
                UIHelper.getElementsAction().swipForScrollableDown(UIHelper.getPushElements().getList(),1f);
                Point p1 = UIHelper.getElementsAction().getElementConcent(u2);
                b = UIHelper.getElementsAction().isBottom(u2) ? true : (p.equals(p1));
            }
            Log.v("UIAUTOMATOR", "testPush: " + b);
        }
    }
}
